﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace TS2000Control.UserControls
{
    public partial class BandsUserControl : UserControl
    {
        public delegate void BandChangedEventHandler(object Sender);

        public event BandChangedEventHandler BandChanged;

        public double Frequency;
        public TS2000ControlLibrary.OperatingMode Mode = TS2000ControlLibrary.OperatingMode.AM;

        public BandsUserControl()
        {
            InitializeComponent();
        }



        protected virtual void OnBandChanged(object sender)
        {
            if (BandChanged != null)
                BandChanged(sender);
        }

        private void btnCBGo_Click(object sender, EventArgs e)
        {
            int ch = (int)nudCBChannel.Value;

            double[] freqs = new double[40]
            { 
                26.965, 26.975, 26.985, 27.005, 27.015, 27.025, 27.035, 27.055, 27.065, 27.075,
                27.085, 27.105, 27.115, 27.125, 27.135, 27.155, 27.165, 27.175, 27.185, 27.205,
                27.215, 27.225, 27.255, 27.235, 27.245, 27.265, 27.275, 27.285, 27.295, 27.305, 
                27.315, 27.325, 27.335, 27.345, 27.355, 27.365, 27.375, 27.385, 27.395, 27.405
            };

            Frequency = freqs[ch - 1];
            Mode = TS2000ControlLibrary.OperatingMode.AM;

            OnBandChanged(this);
        }

        private void button_Click(object sender, EventArgs e)
        {
            string btn = ((Button)sender).Text;

            switch (btn)
            {
                case "160m": Frequency = 1.9; Mode = TS2000ControlLibrary.OperatingMode.USB; break;
                case "80m": Frequency = 3.8; Mode = TS2000ControlLibrary.OperatingMode.LSB; break;
                case "40m": Frequency = 7.175; Mode = TS2000ControlLibrary.OperatingMode.LSB; break;
                case "20m": Frequency = 14.225; Mode = TS2000ControlLibrary.OperatingMode.USB; break;
                case "17m": Frequency = 18.11; Mode = TS2000ControlLibrary.OperatingMode.USB; break;
                case "15m": Frequency = 21.275; Mode = TS2000ControlLibrary.OperatingMode.LSB; break;
                case "12m": Frequency = 24.930; Mode = TS2000ControlLibrary.OperatingMode.LSB; break;
                case "10m": Frequency = 28.5; Mode = TS2000ControlLibrary.OperatingMode.LSB; break;
                case "6m": Frequency = 50; Mode = TS2000ControlLibrary.OperatingMode.FM; break;
                case "2m": Frequency = 144.1; Mode = TS2000ControlLibrary.OperatingMode.FM; break;
                case "70cm": Frequency = 420; Mode = TS2000ControlLibrary.OperatingMode.FM; break;
                case "5 Mhz": Frequency = 5; Mode = TS2000ControlLibrary.OperatingMode.AM; break;
                case "10 Mhz": Frequency = 10; Mode = TS2000ControlLibrary.OperatingMode.AM; break;

                case "120m": Frequency = 2.3; Mode = TS2000ControlLibrary.OperatingMode.AM; break;
                case "90m": Frequency = 3.2; Mode = TS2000ControlLibrary.OperatingMode.AM; break;
                case "75m": Frequency = 3.9; Mode = TS2000ControlLibrary.OperatingMode.AM; break;
                case "60m": Frequency = 4.75; Mode = TS2000ControlLibrary.OperatingMode.AM; break;
                case "49m": Frequency = 5.9; Mode = TS2000ControlLibrary.OperatingMode.AM; break;
                case "41m": Frequency = 7.2; Mode = TS2000ControlLibrary.OperatingMode.AM; break;
                case "31m": Frequency = 9.4; Mode = TS2000ControlLibrary.OperatingMode.AM; break;
                case "25m": Frequency = 11.6; Mode = TS2000ControlLibrary.OperatingMode.AM; break;
                case "22m": Frequency = 13.57; Mode = TS2000ControlLibrary.OperatingMode.AM; break;
                case "19m": Frequency = 15.1; Mode = TS2000ControlLibrary.OperatingMode.AM; break;
                case "16m": Frequency = 17.48; Mode = TS2000ControlLibrary.OperatingMode.AM; break;
                case "13m": Frequency = 21.45; Mode = TS2000ControlLibrary.OperatingMode.AM; break;
                case "11m": Frequency = 25.6; Mode = TS2000ControlLibrary.OperatingMode.AM; break;

                case "LW": Frequency = 0.030; Mode = TS2000ControlLibrary.OperatingMode.AM; break;
                case "MW": Frequency = 0.535; Mode = TS2000ControlLibrary.OperatingMode.AM; break;
            }

            OnBandChanged(this);
        }







    }
}
